//
//  NSURL+Signature.m
//  FunnyVideo
//
//  Created by 李鑫 on 15/9/1.
//  Copyright © 2015年 NewEggTech. All rights reserved.
//

#import "NSURL+Signature.h"
#import "TXYRequestManger.h"

@implementation NSURL (Signature)


- (NSURL *)signatureURLOnce{
    NSString *cov_str = [self absoluteString];
    
    if([[TXYRequestManger sharedRequestManger] cachedPersSig])
    {
        NSString *newURLStr = [cov_str stringByAppendingString:[NSString stringWithFormat:@"?sign=%@",[[TXYRequestManger sharedRequestManger] cachedPersSig]]];
        
        return [NSURL URLWithString:newURLStr];
    }
    
    NSString *newURLStr = [cov_str stringByAppendingString:[NSString stringWithFormat:@"?sign=%@",[[TXYRequestManger sharedRequestManger] requestSignatureBucketName:TXYBucket type:TXYSignaturePersistant]]];
    
    
    return [NSURL URLWithString:newURLStr];
}

- (NSURL *)signatureURLPersistant{
    NSString *cov_str = [self absoluteString];
    
    if([[TXYRequestManger sharedRequestManger] cachedPersSig])
    {
        NSString *newURLStr = [cov_str stringByAppendingString:[NSString stringWithFormat:@"?sign=%@",[[TXYRequestManger sharedRequestManger] cachedPersSig]]];
        
        return [NSURL URLWithString:newURLStr];
    }
    
    NSString *newURLStr = [cov_str stringByAppendingString:[NSString stringWithFormat:@"?sign=%@",[[TXYRequestManger sharedRequestManger] requestSignatureBucketName:TXYBucket type:TXYSignaturePersistant]]];
    
    
    return [NSURL URLWithString:newURLStr];
}
@end
